import { IconNode } from '@/types/graph'
import { defineStore } from 'pinia'
interface Group {
    group:any,
    icons:IconNode[]
}
export const useGraph =  defineStore({
    id: "useGraph",
    state:():Group=>{
        return {
            group:[],
            icons:[
                {
                    id: "0",
                    label: "圆形",
                    type: "circle-node",
                    icon: "yuanxingweixuanzhong",
                    size: 40,
                    style: {
                        lineWidth: 2,
                        cursor: "pointer"
                    },
                },
                {
                    id: "01",
                    label: "五角星",
                    type: "star-node",
                    icon: "wujiaoxingkong",
                    size: 40,
                    style: {
                        lineWidth: 2,
                        cursor: "pointer"
                    },
                },
                {
                    id: "2",
                    label: "长方形",
                    type: "rect-node",
                    icon: "tx-changfangxing",
                    size: [100, 36],
                    style: {
                        lineWidth: 2,
                        cursor: "pointer"
                    },
                },
                {
                    id: "3",
                    label: "三角形",
                    type: "triangle-node",
                    icon: "triangle",
                    size: 40,
                    style: {
                        lineWidth: 2,
                        cursor: "pointer"
                    },
                },
                {
                    id: "4",
                    label: "圆形容器",
                    type: "circle",
                    icon: "rongqifuwuContainerServi",
                    size: [80, 80],
                    style: {
                        lineWidth: 2,
                        cursor: "pointer"
                    },
                },
                {
                    id: "5",
                    label: "方形容器",
                    type: "rect",
                    icon: "rongqi",
                    size: [100, 50],
                    style: {
                        lineWidth: 2,
                        cursor: "pointer"
                    },
                },
            ]
        }
    },
    // 开启持久化
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'useGraph',  //自定义 Key值
                storage: localStorage,  // 选择存储方式
            },
        ],
    },
    actions:{
        // 获取自定义combo的列表
        getGroupList() {
            return this.group
        },
        // 添加自定义combo的列表
        addGroupList(item:any) {
            this.group.push(item)
        },
        // 删除自定义combo的列表
        removeGroupList(item:any) {
            this.group = this.group.map((ele:any) => {
                if (ele.id === item.id) return 
                return ele
            }).filter(Boolean)
        },
    }
})